Package com.rnett.plugin.naming

The com.rnett.plugin.naming package provides ways to get FqNames and IR symbols for declarations. It primarily provides a structured method based on nested objects, but also provides direct access. Each of these reference types exposes the FqName of the element, and can be resolved with an IrPluginContext. Function, property, and constructor references all accept filters (essentially (IrSimpleFunction) -> Boolean lambdas or the equivalent, but with some helper methods for common conditions) to disambiguate overloads. Some utility functions are provided in HasContext for working with references in IR, such as irCall(FunctionRef) or ClassRef.resolveTypeWith.

Structured

The structured name resolution can be seen in the stdlib names . Objects extending RootPackage, PackageRef, and ClassRef can be nested, each auto-detecting the name from the object named and adding its parent's name as a prefix to its own. This requires the compiler plugin since there is no inner object or object delegation. However, if both name and parent are specified the compiler plugin is unnecessary. Property, function, and constructor references can be created inside of class or package references (with constructor references in packages requiring the class name). Note that just like in IR, extension receivers are not part of an element's FqName, only dispatch receivers.

Direct

Methods to directly get references are also provided for classes, functions, properties, and constructors. Literal versions are also provided, that take a class, function, property, or class literal, respectively. Using the literal versions requires the compiler plugin, since the FqNames of the literals will be resolved at compile time. The getFqName(literal) and literal.fqName() functions work similarly, and also require the compiler plugin. Note that all of these literal functions only work with literal arguments for the declaration being resolved (thus the name), not variables or parameters.

Types

typeOf()-like type resolution methods are also provided. They enable getting a TypeRef from a type literal with typeRef<T>(), which can be resolved to an IrType later with an IrPluginContext or HasContext. They can also be compared to IrTypes without resolving using eq. Methods using eq such as IrType.isType<T>() and IrType.isClassifierOf<T>() are also provided. The classifier of a TypeRef is a ClassRef, which provides another method for resolving classes.

Types

BaseReference
Link copied to clipboard
sealed class BaseReference
ClassRef
Link copied to clipboard
abstract class ClassRef(name: String, parent: Namespace?) : Namespace, Reference<IrClassSymbol>

A class reference. Should be the superclass of an object inside another Namespace. The parent will be auto-filled (at compile time), as will the name if not set. The parent will be the enclosing object, which must be a Namespace. By default, the name is the object name.

ConstructorFilter
Link copied to clipboard
open class ConstructorFilter : IConstructorFilter

Implementation of IConstructorFilter

ConstructorRef
Link copied to clipboard
class ConstructorRef : BaseReference, Reference<IrConstructorSymbol> , IConstructorFilter

A constructor reference that gets the constructor of the parent class matching the filter.

FunctionFilter
Link copied to clipboard
open class FunctionFilter : IFunctionFilter

Implementation of IFunctionFilter

FunctionRef
Link copied to clipboard
class FunctionRef : BaseReference, Reference<IrSimpleFunctionSymbol> , IFunctionFilter

A function reference that gets the function matching the name and filter.

FunctionRefDelegate
Link copied to clipboard
class FunctionRefDelegate : FunctionFilter, ReadOnlyProperty<Any?, FunctionRef>

A delegate to get a FunctionRef with the property's name

IConstructorFilter
Link copied to clipboard
interface IConstructorFilter

A filter for resolving IR constructors.

IFunctionFilter
Link copied to clipboard
interface IFunctionFilter

A filter for resolving IR functions

IPropertyFilter
Link copied to clipboard
interface IPropertyFilter

A filter for resolving IR properties

Namespace
Link copied to clipboard
sealed class Namespace : BaseReference

A namespace that defiens a FqName. Either a class or package for now.

PackageRef
Link copied to clipboard
abstract class PackageRef(name: String, parent: Namespace?) : Namespace

A package reference. Should be the superclass of an object inside another Namespace. The parent will be auto-filled (at compile time), as will the name if not set. The parent will be the enclosing object, which must be a Namespace. By default, the name is the lower case object name.

PropertyFilter
Link copied to clipboard
open class PropertyFilter : IPropertyFilter

Implementation of IPropertyFilter

PropertyRef
Link copied to clipboard
class PropertyRef : BaseReference, Reference<IrPropertySymbol> , IPropertyFilter

A property reference that gets the property matching the name and filter.

PropertyRefDelegate
Link copied to clipboard
class PropertyRefDelegate : PropertyFilter, ReadOnlyProperty<Any?, PropertyRef>

A delegate to get a PropertyRef with the property's name

Reference
Link copied to clipboard
interface Reference<S : IrBindableSymbol<*, *>>

A reference that is resolvable to an IR symbol via a IrPluginContext

RootPackage
Link copied to clipboard
open class RootPackage(name: String) : Namespace

A package with no parent. Does not have to be a single package (i.e. name can have .s).

StarRef
Link copied to clipboard
object StarRef : TypeProjectionRef
TypeProjectionRef
Link copied to clipboard
sealed class TypeProjectionRef
TypeRef
Link copied to clipboard
data class TypeRef(classifier: ClassRef, nullable: Boolean, arguments: List<TypeProjectionRef>, variance: TypeRefVariance) : TypeProjectionRef
TypeRefVariance
Link copied to clipboard
enum TypeRefVariance : Enum<TypeRefVariance>

Functions

Class
Link copied to clipboard
fun Namespace.Class(): PropertyDelegateProvider<Any?, ClassRef>

Create a ClassRef with the property's name, with the current Namespace as its parent.

fun Class(ref: KClass<*>): ClassRef

Create a ClassRef from a class reference. ref must be a literal, it can not be a variable.

fun Class(fqName: FqName): ClassRef

Create a ClassRef from a FqName. No parent is used.

fun Namespace.Class(name: String): ClassRef

Create a ClassRef with the given name, with the current Namespace as its parent.

constructor
Link copied to clipboard
fun ClassRef.constructor(filter: IConstructorFilter.() -> Unit): ConstructorRef

Get a constructor from this ClassRef that matches filter.

fun constructor(ref: KClass<*>, filter: ConstructorFilter.() -> Unit = {}): ConstructorRef

Get a constructor from the given class literal matching filter. Must be called with a literal.

fun constructor(fqClassName: FqName, filter: ConstructorFilter.() -> Unit = {}): ConstructorRef

Get a constructor from the class with fqClassName, matching filter.

fun PackageRef.constructor(className: String, filter: ConstructorFilter.() -> Unit = {}): ConstructorRef

Get a constructor for the class with className in this PackageRef, matching filter.

fun RootPackage.constructor(className: String, filter: ConstructorFilter.() -> Unit = {}): ConstructorRef

Get a constructor for the class with className in this RootPackage, matching filter.

descendant
Link copied to clipboard
fun FqName.descendant(id: String): FqName

Get the descendant of a FqName (i.e. child but id may include .). Returns this if id is blank.

eq
Link copied to clipboard
infix fun IrType.eq(other: TypeRef): Boolean
fqName
Link copied to clipboard
fun KCallable<*>.fqName(): FqName
fun KClass<*>.fqName(): FqName

Has to be called directly on the literal (i.e. not on a reference passed as a parameter). Will be replaced during compilation.

function
Link copied to clipboard
fun Namespace.function(filter: FunctionFilter.() -> Unit = {}): FunctionRefDelegate

Get a function delegate in the current Namespace with the property's name, matching filter

fun function(ref: KFunction<*>, filter: FunctionFilter.() -> Unit = {}): FunctionRef

Get a function from a function literal. Can only be called on literals, not variables.

fun function(fqName: FqName, filter: FunctionFilter.() -> Unit = {}): FunctionRef

Get a function with fqName, matching filter

fun Namespace.function(name: String, filter: FunctionFilter.() -> Unit = {}): FunctionRef

Get a function in the current Namespace with the given name, matching filter

getFqName
Link copied to clipboard
fun getFqName(element: KCallable<*>): FqName
fun getFqName(element: KClass<*>): FqName

Has to be called directly on the literal (i.e. not on a reference passed as a parameter). Will be replaced during compilation.

invoke
Link copied to clipboard
inline operator fun <T : IConstructorFilter> T.invoke(builder: IConstructorFilter.() -> Unit): T
inline operator fun <T : IFunctionFilter> T.invoke(builder: IFunctionFilter.() -> Unit): T
inline operator fun <T : IPropertyFilter> T.invoke(builder: IPropertyFilter.() -> Unit): T
isClassifierOf
Link copied to clipboard
inline fun <T> IrType.isClassifierOf(): Boolean
fun IrType.isClassifierOf(classRef: ClassRef): Boolean
isType
Link copied to clipboard
inline fun <T> IrType.isType(): Boolean
primaryConstructor
Link copied to clipboard
fun ClassRef.primaryConstructor(filter: IConstructorFilter.() -> Unit = {}): ConstructorRef

Get the primary constructor from this ClassRef that matches filter.

fun primaryConstructor(ref: KClass<*>, filter: ConstructorFilter.() -> Unit = {}): ConstructorRef

Get the primary constructor from the given class literal matching filter. Must be called with a literal.

fun primaryConstructor(fqClassName: FqName, filter: ConstructorFilter.() -> Unit = {}): ConstructorRef

Get the primary constructor from the class with fqClassName, matching filter.

fun PackageRef.primaryConstructor(className: String, filter: ConstructorFilter.() -> Unit = {}): ConstructorRef

Get the primary constructor for the class with className in this PackageRef, matching filter.

fun RootPackage.primaryConstructor(className: String, filter: ConstructorFilter.() -> Unit = {}): ConstructorRef

Get the primary constructor for the class with className in this RootPackage, matching filter.

property
Link copied to clipboard
fun Namespace.property(filter: PropertyFilter.() -> Unit = {}): PropertyRefDelegate

Get a property delegate in the current Namespace with the property's name, matching filter

fun property(ref: KProperty<*>, filter: PropertyFilter.() -> Unit = {}): PropertyRef

Get a property from a property literal. Can only be called on literals, not variables.

fun property(fqName: FqName, filter: PropertyFilter.() -> Unit = {}): PropertyRef

Get a property with fqName, matching filter

fun Namespace.property(name: String, filter: PropertyFilter.() -> Unit = {}): PropertyRef

Get a property in the current Namespace with the given name, matching filter

typeRef
Link copied to clipboard
inline fun <T> typeRef(): TypeRef
withExtensionReceiverType
Link copied to clipboard
fun <T : IFunctionFilter> T.withExtensionReceiverType(classRef: () -> ClassRef): T

Only select functions with a matching (lazily resolved) extension receiver

withFilter
Link copied to clipboard
fun <T : IConstructorFilter> T.withFilter(filter: (IrConstructor) -> Boolean): T
fun <T : IPropertyFilter> T.withFilter(filter: (IrProperty) -> Boolean): T

fun <T : IFunctionFilter> T.withFilter(filter: (IrFunction) -> Boolean): T

Add a lambda filter